package q.yazg;

/**
 *
 * @author khalisq
 */
public class Easing {
    
    private float start,change,duration;
    
    private float time;

    public Easing(float start, float end, float duration) {
        this.start = start;
        this.change = end - start;
        this.duration = duration;
        time=-1;
    }
    
    public float update(float t) {
        time+=t;
        float a = time / (duration / 2);
        if (a < 1)
            return change / 2 * a * a + start;
        a--;
        return -change / 2 * (a * (a - 2) - 1) + start;
    }
    
    public boolean isDone(){
        return duration==0 || time>=duration;
    }
    
    public void reset(){
        time=0;
    }
    
    public void reInit(float start, float end, float duration) {
        this.start = start;
        this.change = end-start;
        this.duration = duration;
        time=-1;
    }
    
    @Deprecated
    public static void main(String[] args){
        Easing e = new Easing(50, 100, 100);
        for(int i=0;i<=100;i++)
            System.out.println(i+" : "+e.update(1));
    }
}
